/*EventlogRead.java Reads EventLog.lst file and sends data to EventParser
Copyright (C) 2013  Dmytro Kostiantynovskyi, HartLi

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/
import java.util.ArrayList;

public class EventlogRead {
	private boolean end = false;
	
	public boolean isEnd() {
		return end;
	}
	public void setEnd(boolean end) {
		this.end = end;
	}
	private ArrayList<ArrayList<String>>  lang;
	public EventlogRead(ArrayList<ArrayList<String>>  l) {
		lang = l;
	}
	
	public void readFile(String file){
		try{
			boolean firstStart = true; 
			Parser parser = new Parser(lang);
			Console console = new Console();
			int index = 0;
			while(!end){
				ArrayList<String> lstEvents = FileReader.getFileStrings(file);
				for( ; index < lstEvents.size(); index++){
					if(!firstStart){
						ArrayList<ArrayList<String>> lst = parser.getParsedMessage(lstEvents.get(index));
						if(lst != null && lst.get(0).get(0) != ""){
							console.chat(lst.get(0).get(0), Integer.parseInt(lst.get(0).get(1)), lst.get(0).get(2));
						}
					}
					firstStart=false;
				}
				Thread.sleep(100);
			}
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}
	
	public Runnable run = new Runnable() {
		@Override
		public void run() {
			readFile(Config.serverRootDirectory+"eventlog.lst");
		}		
	};
}
